Imports MySql.Data.MySqlClient
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Data.SqlServerCe
Imports System.Data.OracleClient
Imports System.Data
Imports DTO
Public Class NGUOIDUNGDao
    Inherits AbstractDao
#Region "New"
    Public Sub New(ByVal connection As KetNoiDto)
        MyBase.New(connection)
    End Sub
    Public Sub New(ByVal ID As System.Int32, ByVal connection As KetNoiDto)
        MyBase.New("NGUOIDUNG", "select * from NGUOIDUNG where ID=" & ID & "", connection)
    End Sub
#End Region
    Public Sub Them(ByVal Dto As NGUOIDUNGdto)
        Dim strsql As String
        strsql = "Insert into NGUOIDUNG(TenDangNhap,MatKhau,IdNV,IdQuyen) values (?,?,?,?)"
        Moketnoi()
        Select Case Ketnoi.MsSql
            Case Class_KieuDL.Access
                Dim cmd As New OleDbCommand(strsql, Ket_noi_Access)
                cmd.Parameters.Add("@TenDangNhap", OleDbType.VarWChar)
                cmd.Parameters.Add("@MatKhau", OleDbType.VarWChar)
                cmd.Parameters.Add("@IdNV", OleDbType.Integer)
                cmd.Parameters.Add("@IdQuyen", OleDbType.Integer)
                cmd.Parameters("@TenDangNhap").Value = Dto.TenDangNhap
                cmd.Parameters("@MatKhau").Value = Dto.MatKhau
                cmd.Parameters("@IdNV").Value = Dto.IdNV
                cmd.Parameters("@IdQuyen").Value = Dto.IdQuyen
                cmd.ExecuteNonQuery()
                strsql = "Select @@IDENTITY"
                cmd = New OleDbCommand(strsql, Ket_noi_Access)
                Dto.ID = cmd.ExecuteScalar()
            Case Class_KieuDL.sql, Class_KieuDL.sqlExpress
                strsql = "Insert into NGUOIDUNG(TenDangNhap,MatKhau,IdNV,IdQuyen) values (@TenDangNhap,@MatKhau,@IdNV,@IdQuyen)"
                Dim cmd As New SqlCommand(strsql, Ket_noi_Sql)
                cmd.Parameters.Add("@TenDangNhap", SqlDbType.NVarChar)
                cmd.Parameters.Add("@MatKhau", SqlDbType.NVarChar)
                cmd.Parameters.Add("@IdNV", SqlDbType.Int)
                cmd.Parameters.Add("@IdQuyen", SqlDbType.Int)
                cmd.Parameters("@TenDangNhap").Value = Dto.TenDangNhap
                cmd.Parameters("@MatKhau").Value = Dto.MatKhau
                cmd.Parameters("@IdNV").Value = Dto.IdNV
                cmd.Parameters("@IdQuyen").Value = Dto.IdQuyen
                cmd.ExecuteNonQuery()
                strsql = "Select @@IDENTITY"
                cmd = New SqlCommand(strsql, Ket_noi_Sql)
                Dto.ID = cmd.ExecuteScalar()
            Case Class_KieuDL.SqlCe
                strsql = "Insert into NGUOIDUNG(TenDangNhap,MatKhau,IdNV,IdQuyen) values (@TenDangNhap,@MatKhau,@IdNV,@IdQuyen)"
                Dim cmd As New SqlCeCommand(strsql, Ket_noi_SqlCe)
                cmd.Parameters("@TenDangNhap").Value = Dto.TenDangNhap
                cmd.Parameters("@MatKhau").Value = Dto.MatKhau
                cmd.Parameters("@IdNV").Value = Dto.IdNV
                cmd.Parameters("@IdQuyen").Value = Dto.IdQuyen
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.Oracle
                strsql = "Insert into NGUOIDUNG(TenDangNhap,MatKhau,IdNV,IdQuyen) values (@TenDangNhap,@MatKhau,@IdNV,@IdQuyen)"
                Dim cmd As New OracleCommand(strsql, Ket_noi_Oracle)
                cmd.Parameters("@TenDangNhap").Value = Dto.TenDangNhap
                cmd.Parameters("@MatKhau").Value = Dto.MatKhau
                cmd.Parameters("@IdNV").Value = Dto.IdNV
                cmd.Parameters("@IdQuyen").Value = Dto.IdQuyen
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.MySql
                strsql = "Insert into NGUOIDUNG(TenDangNhap,MatKhau,IdNV,IdQuyen) values (@TenDangNhap,@MatKhau,@IdNV,@IdQuyen)"
                Dim cmd As New MySqlCommand(strsql, Ket_noi_MySql)
                cmd.Parameters.Add("@TenDangNhap", MySqlDbType.String)
                cmd.Parameters.Add("@MatKhau", MySqlDbType.String)
                cmd.Parameters.Add("@IdNV", MySqlDbType.Int32)
                cmd.Parameters.Add("@IdQuyen", MySqlDbType.Int32)
                cmd.Parameters("@TenDangNhap").Value = Dto.TenDangNhap
                cmd.Parameters("@MatKhau").Value = Dto.MatKhau
                cmd.Parameters("@IdNV").Value = Dto.IdNV
                cmd.Parameters("@IdQuyen").Value = Dto.IdQuyen
                cmd.ExecuteNonQuery()
        End Select
        Ngatketnoi()
    End Sub
    Public Sub Xoa(ByVal ID As System.Int32)
        Dim strSQL As String
        Moketnoi()
        Select Case Ketnoi.MsSql
            Case Class_KieuDL.Access
                strSQL = "Delete From NGUOIDUNG Where ID= ? "
                Dim cmd As New OleDbCommand(strSQL, Ket_noi_Access)
                cmd.Parameters.Add("@ID", OleDbType.Integer).Value = ID
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.sql, Class_KieuDL.sqlExpress
                strSQL = "Delete From NGUOIDUNG Where ID= @ID"
                Dim cmd As New SqlCommand(strSQL, Ket_noi_Sql)
                cmd.Parameters.Add("@ID", SqlDbType.Int).Value = ID
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.SqlCe
                strSQL = "Delete From NGUOIDUNG Where ID=" & ID & ""
                Dim cmd As New SqlCeCommand(strSQL, Ket_noi_SqlCe)
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.Oracle
                strSQL = "Delete From NGUOIDUNG Where ID=" & ID & ""
                Dim cmd As New OracleCommand(strSQL, Ket_noi_Oracle)
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.MySql
                strSQL = "Delete From NGUOIDUNG Where ID=" & ID & ""
                Dim cmd As New MySqlCommand(strSQL, Ket_noi_MySql)
                cmd.ExecuteNonQuery()
        End Select
        Ngatketnoi()
    End Sub
    Public Sub sua(ByVal dto As NGUOIDUNGdto)
        Dim strSQL As String
        Moketnoi()
        Select Case Ketnoi.MsSql
            Case Class_KieuDL.Access
                strSQL = "Update NGUOIDUNG Set TenDangNhap=? ,MatKhau=? ,IdNV=? ,IdQuyen= ? where ID= ? "
                Dim cmd As New OleDbCommand(strSQL, Ket_noi_Access)
                cmd.Parameters.Add("@TenDangNhap", OleDbType.VarWChar)
                cmd.Parameters.Add("@MatKhau", OleDbType.VarWChar)
                cmd.Parameters.Add("@IdNV", OleDbType.Integer)
                cmd.Parameters.Add("@IdQuyen", OleDbType.Integer)
                cmd.Parameters.Add("@ID", OleDbType.Integer)
                cmd.Parameters("@TenDangNhap").Value = dto.TenDangNhap
                cmd.Parameters("@MatKhau").Value = dto.MatKhau
                cmd.Parameters("@IdNV").Value = dto.IdNV
                cmd.Parameters("@IdQuyen").Value = dto.IdQuyen
                cmd.Parameters("@ID").Value = dto.ID
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.sql, Class_KieuDL.sqlExpress
                strSQL = "Update NGUOIDUNG Set TenDangNhap= @TenDangNhap , MatKhau= @MatKhau , IdNV= @IdNV , IdQuyen= @IdQuyen where ID= @ID"
                Dim cmd As New SqlCommand(strSQL, Ket_noi_Sql)
                cmd.Parameters.Add("@TenDangNhap", SqlDbType.NVarChar)
                cmd.Parameters.Add("@MatKhau", SqlDbType.NVarChar)
                cmd.Parameters.Add("@IdNV", SqlDbType.Int)
                cmd.Parameters.Add("@IdQuyen", SqlDbType.Int)
                cmd.Parameters.Add("@ID", SqlDbType.Int)
                cmd.Parameters("@TenDangNhap").Value = dto.TenDangNhap
                cmd.Parameters("@MatKhau").Value = dto.MatKhau
                cmd.Parameters("@IdNV").Value = dto.IdNV
                cmd.Parameters("@IdQuyen").Value = dto.IdQuyen
                cmd.Parameters("@ID").Value = dto.ID
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.SqlCe
                strSQL = "Update NGUOIDUNG Set TenDangNhap= @TenDangNhap , MatKhau= @MatKhau , IdNV= @IdNV , IdQuyen= @IdQuyen where ID= @ID"
                Dim cmd As New SqlCeCommand(strSQL, Ket_noi_SqlCe)
                cmd.Parameters("@TenDangNhap").Value = dto.TenDangNhap
                cmd.Parameters("@MatKhau").Value = dto.MatKhau
                cmd.Parameters("@IdNV").Value = dto.IdNV
                cmd.Parameters("@IdQuyen").Value = dto.IdQuyen
                cmd.Parameters("@ID").Value = dto.ID
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.Oracle
                strSQL = "Update NGUOIDUNG Set TenDangNhap= @TenDangNhap , MatKhau= @MatKhau , IdNV= @IdNV , IdQuyen= @IdQuyen where ID= @ID"
                Dim cmd As New OracleCommand(strSQL, Ket_noi_Oracle)
                cmd.Parameters("@TenDangNhap").Value = dto.TenDangNhap
                cmd.Parameters("@MatKhau").Value = dto.MatKhau
                cmd.Parameters("@IdNV").Value = dto.IdNV
                cmd.Parameters("@IdQuyen").Value = dto.IdQuyen
                cmd.Parameters("@ID").Value = dto.ID
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.MySql
                strSQL = "Update NGUOIDUNG Set TenDangNhap= @TenDangNhap , MatKhau= @MatKhau , IdNV= @IdNV , IdQuyen= @IdQuyen where ID= @ID"
                Dim cmd As New MySqlCommand(strSQL, Ket_noi_MySql)
                cmd.Parameters.Add("@TenDangNhap", MySqlDbType.String)
                cmd.Parameters.Add("@MatKhau", MySqlDbType.String)
                cmd.Parameters.Add("@IdNV", MySqlDbType.Int32)
                cmd.Parameters.Add("@IdQuyen", MySqlDbType.Int32)
                cmd.Parameters.Add("@ID", MySqlDbType.Int32)
                cmd.Parameters("@TenDangNhap").Value = dto.TenDangNhap
                cmd.Parameters("@MatKhau").Value = dto.MatKhau
                cmd.Parameters("@IdNV").Value = dto.IdNV
                cmd.Parameters("@IdQuyen").Value = dto.IdQuyen
                cmd.Parameters("@ID").Value = dto.ID
                cmd.ExecuteNonQuery()
        End Select
        Ngatketnoi()
    End Sub
    Public Sub SuaTenDangNhap(ByVal TenDangNhap As System.String, ByVal ID As System.Int32)
        Dim strSQL As String
        Moketnoi()
        Select Case Ketnoi.MsSql
            Case Class_KieuDL.Access
                strSQL = "Update NGUOIDUNG Set TenDangNhap = ?  where ID= ? "
                Dim cmd As New OleDbCommand(strSQL, Ket_noi_Access)
                cmd.Parameters.Add("@TenDangNhap", OleDbType.VarWChar)
                cmd.Parameters.Add("@ID", OleDbType.Integer)
                cmd.Parameters("@TenDangNhap").Value = TenDangNhap
                cmd.Parameters("@ID").Value = ID
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.sql, Class_KieuDL.sqlExpress
                strSQL = "Update NGUOIDUNG Set TenDangNhap = @TenDangNhap  where ID= @ID"
                Dim cmd As New SqlCommand(strSQL, Ket_noi_Sql)
                cmd.Parameters.Add("@TenDangNhap", SqlDbType.NVarChar)
                cmd.Parameters.Add("@ID", SqlDbType.Int)
                cmd.Parameters("@TenDangNhap").Value = TenDangNhap
                cmd.Parameters("@ID").Value = ID
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.SqlCe
                strSQL = "Update NGUOIDUNG Set TenDangNhap =" & TenDangNhap & "  where ID=" & ID & ""
                Dim cmd As New SqlCeCommand(strSQL, Ket_noi_SqlCe)
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.Oracle
                strSQL = "Update NGUOIDUNG Set TenDangNhap =" & TenDangNhap & "  where ID=" & ID & ""
                Dim cmd As New OracleCommand(strSQL, Ket_noi_Oracle)
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.MySql
                strSQL = "Update NGUOIDUNG Set TenDangNhap =" & TenDangNhap & "  where ID=" & ID & ""
                Dim cmd As New MySqlCommand(strSQL, Ket_noi_MySql)
                cmd.ExecuteNonQuery()
        End Select
        Ngatketnoi()
    End Sub
    Public Sub SuaMatKhau(ByVal MatKhau As System.String, ByVal ID As System.Int32)
        Dim strSQL As String
        Moketnoi()
        Select Case Ketnoi.MsSql
            Case Class_KieuDL.Access
                strSQL = "Update NGUOIDUNG Set MatKhau = ?  where ID= ? "
                Dim cmd As New OleDbCommand(strSQL, Ket_noi_Access)
                cmd.Parameters.Add("@MatKhau", OleDbType.VarWChar)
                cmd.Parameters.Add("@ID", OleDbType.Integer)
                cmd.Parameters("@MatKhau").Value = MatKhau
                cmd.Parameters("@ID").Value = ID
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.sql, Class_KieuDL.sqlExpress
                strSQL = "Update NGUOIDUNG Set MatKhau = @MatKhau  where ID= @ID"
                Dim cmd As New SqlCommand(strSQL, Ket_noi_Sql)
                cmd.Parameters.Add("@MatKhau", SqlDbType.NVarChar)
                cmd.Parameters.Add("@ID", SqlDbType.Int)
                cmd.Parameters("@MatKhau").Value = MatKhau
                cmd.Parameters("@ID").Value = ID
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.SqlCe
                strSQL = "Update NGUOIDUNG Set MatKhau =" & MatKhau & "  where ID=" & ID & ""
                Dim cmd As New SqlCeCommand(strSQL, Ket_noi_SqlCe)
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.Oracle
                strSQL = "Update NGUOIDUNG Set MatKhau =" & MatKhau & "  where ID=" & ID & ""
                Dim cmd As New OracleCommand(strSQL, Ket_noi_Oracle)
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.MySql
                strSQL = "Update NGUOIDUNG Set MatKhau =" & MatKhau & "  where ID=" & ID & ""
                Dim cmd As New MySqlCommand(strSQL, Ket_noi_MySql)
                cmd.ExecuteNonQuery()
        End Select
        Ngatketnoi()
    End Sub
    Public Sub SuaIdNV(ByVal IdNV As System.Int32, ByVal ID As System.Int32)
        Dim strSQL As String
        Moketnoi()
        Select Case Ketnoi.MsSql
            Case Class_KieuDL.Access
                strSQL = "Update NGUOIDUNG Set IdNV = ?  where ID= ? "
                Dim cmd As New OleDbCommand(strSQL, Ket_noi_Access)
                cmd.Parameters.Add("@IdNV", OleDbType.Integer)
                cmd.Parameters.Add("@ID", OleDbType.Integer)
                cmd.Parameters("@IdNV").Value = IdNV
                cmd.Parameters("@ID").Value = ID
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.sql, Class_KieuDL.sqlExpress
                strSQL = "Update NGUOIDUNG Set IdNV = @IdNV  where ID= @ID"
                Dim cmd As New SqlCommand(strSQL, Ket_noi_Sql)
                cmd.Parameters.Add("@IdNV", SqlDbType.Int)
                cmd.Parameters.Add("@ID", SqlDbType.Int)
                cmd.Parameters("@IdNV").Value = IdNV
                cmd.Parameters("@ID").Value = ID
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.SqlCe
                strSQL = "Update NGUOIDUNG Set IdNV =" & IdNV & "  where ID=" & ID & ""
                Dim cmd As New SqlCeCommand(strSQL, Ket_noi_SqlCe)
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.Oracle
                strSQL = "Update NGUOIDUNG Set IdNV =" & IdNV & "  where ID=" & ID & ""
                Dim cmd As New OracleCommand(strSQL, Ket_noi_Oracle)
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.MySql
                strSQL = "Update NGUOIDUNG Set IdNV =" & IdNV & "  where ID=" & ID & ""
                Dim cmd As New MySqlCommand(strSQL, Ket_noi_MySql)
                cmd.ExecuteNonQuery()
        End Select
        Ngatketnoi()
    End Sub
    Public Sub SuaIdQuyen(ByVal IdQuyen As System.Int32, ByVal ID As System.Int32)
        Dim strSQL As String
        Moketnoi()
        Select Case Ketnoi.MsSql
            Case Class_KieuDL.Access
                strSQL = "Update NGUOIDUNG Set IdQuyen = ?  where ID= ? "
                Dim cmd As New OleDbCommand(strSQL, Ket_noi_Access)
                cmd.Parameters.Add("@IdQuyen", OleDbType.Integer)
                cmd.Parameters.Add("@ID", OleDbType.Integer)
                cmd.Parameters("@IdQuyen").Value = IdQuyen
                cmd.Parameters("@ID").Value = ID
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.sql, Class_KieuDL.sqlExpress
                strSQL = "Update NGUOIDUNG Set IdQuyen = @IdQuyen  where ID= @ID"
                Dim cmd As New SqlCommand(strSQL, Ket_noi_Sql)
                cmd.Parameters.Add("@IdQuyen", SqlDbType.Int)
                cmd.Parameters.Add("@ID", SqlDbType.Int)
                cmd.Parameters("@IdQuyen").Value = IdQuyen
                cmd.Parameters("@ID").Value = ID
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.SqlCe
                strSQL = "Update NGUOIDUNG Set IdQuyen =" & IdQuyen & "  where ID=" & ID & ""
                Dim cmd As New SqlCeCommand(strSQL, Ket_noi_SqlCe)
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.Oracle
                strSQL = "Update NGUOIDUNG Set IdQuyen =" & IdQuyen & "  where ID=" & ID & ""
                Dim cmd As New OracleCommand(strSQL, Ket_noi_Oracle)
                cmd.ExecuteNonQuery()
            Case Class_KieuDL.MySql
                strSQL = "Update NGUOIDUNG Set IdQuyen =" & IdQuyen & "  where ID=" & ID & ""
                Dim cmd As New MySqlCommand(strSQL, Ket_noi_MySql)
                cmd.ExecuteNonQuery()
        End Select
        Ngatketnoi()
    End Sub
    Public Sub layBang()
        Chuoi_SQL = " SELECT NGUOIDUNG.*, Quyen.TenQuyen" & _
        " FROM NGUOIDUNG INNER JOIN Quyen ON NGUOIDUNG.IdQuyen = Quyen.idQuyen "
        Doc_bang()
    End Sub
    Public Sub layBangTheoID(ByVal ARRAY1 As ArrayList)
        Dim DK As String = ""
        If ARRAY1.Count > 0 Then
            For I As Integer = 0 To ARRAY1.Count - 1
                DK = DK & IIf(DK <> "", " OR ", "") & "ID=" & ARRAY1.Item(I) & ""
            Next
        End If
        If DK <> "" Then DK = " WHERE " & DK
        Chuoi_SQL = " Select * from NGUOIDUNG" & DK
        Doc_bang()
    End Sub
    Public Sub layBangTheoID(ByVal ID As System.Int32)
        Chuoi_SQL = " Select * from NGUOIDUNG where  ID = " & ID & ""
        Doc_bang()
    End Sub
    Public Sub XOABangTheoID(ByVal ID As System.Int32)
        Dim strsql As String
        strsql = "Delete From NGUOIDUNG Where ID=" & ID & ""
        Thuc_hien_lenh(strsql)
    End Sub
    Public Sub layBangTheoTenDangNhap(ByVal ARRAY1 As ArrayList)
        Dim DK As String = ""
        If ARRAY1.Count > 0 Then
            For I As Integer = 0 To ARRAY1.Count - 1
                DK = DK & IIf(DK <> "", " OR ", "") & "TenDangNhap='" & ARRAY1.Item(I) & "'"
            Next
        End If
        If DK <> "" Then DK = " WHERE " & DK
        Chuoi_SQL = " Select * from NGUOIDUNG" & DK
        Doc_bang()
    End Sub
    Public Sub layBangTheoTenDangNhap_like(ByVal TenDangNhap As System.String)
        Chuoi_SQL = " Select * from NGUOIDUNG where  TenDangNhap  like '%" & TenDangNhap & "%'"
        Doc_bang()
    End Sub
    Public Sub layBangTheoTenDangNhap(ByVal TenDangNhap As System.String)
        Chuoi_SQL = " Select * from NGUOIDUNG where  TenDangNhap = '" & TenDangNhap & "'"
        Doc_bang()
    End Sub
    Public Sub XOABangTheoTenDangNhap(ByVal TenDangNhap As System.String)
        Dim strsql As String
        strsql = "Delete From NGUOIDUNG Where TenDangNhap='" & TenDangNhap & "'"
        Thuc_hien_lenh(strsql)
    End Sub
    Public Sub layBangTheoMatKhau(ByVal ARRAY1 As ArrayList)
        Dim DK As String = ""
        If ARRAY1.Count > 0 Then
            For I As Integer = 0 To ARRAY1.Count - 1
                DK = DK & IIf(DK <> "", " OR ", "") & "MatKhau='" & ARRAY1.Item(I) & "'"
            Next
        End If
        If DK <> "" Then DK = " WHERE " & DK
        Chuoi_SQL = " Select * from NGUOIDUNG" & DK
        Doc_bang()
    End Sub
    Public Sub layBangTheoMatKhau_like(ByVal MatKhau As System.String)
        Chuoi_SQL = " Select * from NGUOIDUNG where  MatKhau  like '%" & MatKhau & "%'"
        Doc_bang()
    End Sub
    Public Sub layBangTheoMatKhau(ByVal MatKhau As System.String)
        Chuoi_SQL = " Select * from NGUOIDUNG where  MatKhau = '" & MatKhau & "'"
        Doc_bang()
    End Sub
    Public Sub XOABangTheoMatKhau(ByVal MatKhau As System.String)
        Dim strsql As String
        strsql = "Delete From NGUOIDUNG Where MatKhau='" & MatKhau & "'"
        Thuc_hien_lenh(strsql)
    End Sub
    Public Sub layBangTheoIdNV(ByVal ARRAY1 As ArrayList)
        Dim DK As String = ""
        If ARRAY1.Count > 0 Then
            For I As Integer = 0 To ARRAY1.Count - 1
                DK = DK & IIf(DK <> "", " OR ", "") & "IdNV=" & ARRAY1.Item(I) & ""
            Next
        End If
        If DK <> "" Then DK = " WHERE " & DK
        Chuoi_SQL = " Select * from NGUOIDUNG" & DK
        Doc_bang()
    End Sub
    Public Sub layBangTheoIdNV(ByVal IdNV As System.Int32)
        Chuoi_SQL = " Select * from NGUOIDUNG where  IdNV = " & IdNV & ""
        Doc_bang()
    End Sub
    Public Sub XOABangTheoIdNV(ByVal IdNV As System.Int32)
        Dim strsql As String
        strsql = "Delete From NGUOIDUNG Where IdNV=" & IdNV & ""
        Thuc_hien_lenh(strsql)
    End Sub
    Public Sub layBangTheoIdQuyen(ByVal ARRAY1 As ArrayList)
        Dim DK As String = ""
        If ARRAY1.Count > 0 Then
            For I As Integer = 0 To ARRAY1.Count - 1
                DK = DK & IIf(DK <> "", " OR ", "") & "IdQuyen=" & ARRAY1.Item(I) & ""
            Next
        End If
        If DK <> "" Then DK = " WHERE " & DK
        Chuoi_SQL = " Select * from NGUOIDUNG" & DK
        Doc_bang()
    End Sub
    Public Sub layBangTheoIdQuyen(ByVal IdQuyen As System.Int32)
        Chuoi_SQL = " Select * from NGUOIDUNG where  IdQuyen = " & IdQuyen & ""
        Doc_bang()
    End Sub
    Public Sub XOABangTheoIdQuyen(ByVal IdQuyen As System.Int32)
        Dim strsql As String
        strsql = "Delete From NGUOIDUNG Where IdQuyen=" & IdQuyen & ""
        Thuc_hien_lenh(strsql)
    End Sub
    Public Sub layBangNhieuTable()
        Chuoi_SQL = " Select ID ,TenDangNhap ,MatKhau ,IdNV ,IdQuyen  from NGUOIDUNG"
        Doc_bang()
    End Sub
    Public Sub TaoTable()
        Dim strsql As String
        strsql = ""
        Select Case Ketnoi.MsSql
            Case Class_KieuDL.Access
            Case Class_KieuDL.sql, Class_KieuDL.sqlExpress
                strsql = ""
            Case Class_KieuDL.SqlCe
                strsql = ""
            Case Class_KieuDL.Oracle
                strsql = ""
            Case Else
                strsql = ""
        End Select
        Thuc_hien_lenh(strsql)
    End Sub
#Region "khac"
    Public Sub layBang(ByVal cauhoi1 As System.String, ByVal traloi1 As System.String, ByVal cauhoi2 As String, ByVal traloi2 As System.String)
        Chuoi_SQL = "select * from nguoidung" & _
            " WHERE cauhoi1='" & cauhoi1 & "' AND traloi1='" & traloi1 & "' and " & _
            " cauhoi2='" & cauhoi2 & "' AND traloi2='" & traloi2 & "'"
        Doc_bang()
    End Sub
    Public Sub layBangTheoTenDangNhapMatkhau(ByVal TenDangNhap As System.String, ByVal matkhau As String)
        Chuoi_SQL = " Select * from NGUOIDUNG where  TenDangNhap = '" & TenDangNhap & "' and  MatKhau='" & matkhau & "'"
        Doc_bang()
    End Sub
#End Region
End Class

